package com.yuanlp.mobileplayer.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yuanlp.mobileplayer.R;
import com.yuanlp.mobileplayer.bean.MediaItem;
import com.yuanlp.mobileplayer.utils.Utils;

import java.util.ArrayList;

/**
 * Created by 原立鹏 on 2017/7/16.
 */

public class NetVideoAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<MediaItem> mediaList;
    private Utils utils;
    private static Bitmap bitmap;

    public NetVideoAdapter(Context context, ArrayList<MediaItem> mediaList){
        this.context=context;
        this.mediaList=mediaList;


    }

    @Override
    public int getCount() {
        return mediaList.size();
    }

    @Override
    public Object getItem(int position) {
        return mediaList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder=null;
        if (convertView==null){
            View view = LayoutInflater.from(context).inflate(R.layout.netmedialayout, null);
            convertView=view;
            viewHolder=new ViewHolder();
            viewHolder.iv_icon= (ImageView) convertView.findViewById(R.id.iv_icon);
            viewHolder.tv_name= (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tv_videotitle= (TextView) convertView.findViewById(R.id.tv_videotitle);


            convertView.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) convertView.getTag();
        }

        //得到数据
        MediaItem item=mediaList.get(position);
        viewHolder.tv_name.setText(item.getName());

        viewHolder.tv_videotitle.setText(item.getVideoTitle());

        Glide.with(context).load(item.getCoverImg()).into(viewHolder.iv_icon);
       // x.image().bind(viewHolder.iv_icon,item.getCoverImg());
        return convertView;
    }


    /**
     * 公共的控件类，里面包含每一行要显示的控件
     */
    private static class ViewHolder{
        ImageView iv_icon;
        TextView tv_name;
        TextView tv_time;
        TextView tv_size;

        TextView tv_videotitle;
    }
}
